<template>
  <div class="goods-wrapper">
    <header class="goods-header">{{ title }}</header>
    <div class="goods-list">
      <div class="goods-item" 
      v-for="item in goods" 
      :key="item.goodsId"
      @click="gotoProductDetail(item.goodsId)"
      >
        <van-image class="cover" lazy-load :src="addUrlPrefix(item.goodsCoverImg)" :alt="item.goodsName" />
        <div class="goods-desc">
          <div class="title">{{ item.goodsName }}</div>
          <div class="price">¥{{ item.sellingPrice }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
const {last} = defineProps(['title', 'goods','last'])
const marginBottom = last?'50px':'0px';
const router = useRouter();
const gotoProductDetail = (goodsId)=>{
  router.push(`/product/${goodsId}`);
}
</script>
<style lang="less">
.goods-wrapper {
  margin-bottom: v-bind(marginBottom);
  .goods-header {
    background: #f9f9f9;
    height: 50px;
    line-height: 50px;
    text-align: center;
    color: @primary-color;
    font-size: 16px;
  }
  .goods-list {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    .goods-item {
      width: 50%;
      box-sizing: border-box;
      border-bottom: 1px solid #e9e9e9;
      padding: 10px;
      .cover {
        display: block;
        width: 120px;
        margin: 0 auto;
      }
      .goods-desc {
        text-align: center;
        font-size: 14px;
        padding: 10px 0;
        .title {
          color: #222333;
        }
        .price {
          color: @primary-color;
        }
      }
      &:nth-child(2n + 1) {
        border-right: 1px solid #e9e9e9;
      }
    }
  }
}
</style>
